package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Modifiremaster;
import com.restaurant.service.ModifiremasterService;

public class ModifiremasterServiceImpl implements ModifiremasterService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Modifiremaster addOrModify( Modifiremaster objModifiremaster ) {
       return ( Modifiremaster ) hibernateTemplate.merge( objModifiremaster );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Modifiremaster deleteRecord( Modifiremaster objModifiremaster ) {
       hibernateTemplate.delete( objModifiremaster );
       return objModifiremaster;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Modifiremaster modifyRecord( Modifiremaster objModifiremaster ) {
       return ( Modifiremaster ) hibernateTemplate.merge( objModifiremaster );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Modifiremaster> loadAll() {
       return (List<Modifiremaster>)hibernateTemplate.findByNamedQuery( "Modifiremaster.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Modifiremaster loadByPrimaryKey( Long primaryKey ) {
       return (Modifiremaster) hibernateTemplate.get( Modifiremaster.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Modifiremaster deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Modifiremaster> loadByHql(String query) {
       return ( List<Modifiremaster> ) hibernateTemplate.find( query );
   }
}